/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JLogin.java
 *
 * Created on 28.04.2011, 06:18:29
 */

package gui;

import javax.swing.JOptionPane;

import superkigav.shared.rightsmanagement.IRights;
import superkigav.shared.rightsmanagement.UserTicket;
import jersey.RightsClient;

/**
 *
 * @author Home
 */
public class JLogin extends javax.swing.JFrame {

    /** Creates new form JLogin */
    public JLogin() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtUsername = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Bitte geben Sie Ihren Benutzernamen und das dazugehörige Passwort ein:");

        jLabel2.setText("Benutzername:");

        txtUsername.setName(""); // NOI18N

        jLabel3.setText("Passwort:");

        jButton1.setText("Einloggen");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Beenden");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(txtUsername, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2)))))
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        IRights client = new RightsClient();
        UserTicket user = client.authenticate(txtUsername.getText(), txtPassword.getText());

        if (user == null) {
            JOptionPane.showMessageDialog(null, "Login ungültig, bitte überprüfen Sie ihre Eingabe.", "Fehler:", JOptionPane.ERROR_MESSAGE);
        } else {
            JElternAnsicht fenster = new JElternAnsicht(user);
            fenster.setVisible(true);

            this.setVisible(false);
        }


/*
        DBConnector SuperKigaV = new DBConnectorImpl();

        Gruppe gruppe1 = new GruppeImpl("Gruppe1", Gruppenart.GANZTAG, true,
                        false, 3);
        Gruppe gruppe2 = new GruppeImpl("Gruppe2", Gruppenart.NACHMITTAG, false,
                        true, 3);
        Gruppe gruppe3 = new GruppeImpl("Gruppe3", Gruppenart.VORMITTAG, false,
                        false, 4);

        SuperKigaV.updateGruppe(gruppe1);
        SuperKigaV.updateGruppe(gruppe2);
        SuperKigaV.updateGruppe(gruppe3);

        Eltern wir = new ElternImpl("Wir");
        Eltern ihr = new ElternImpl("Ihr");

        Kind kind1 = new KindImpl(wir, "Peter", "M�ller", Geschlecht.MAENNLICH);
        Kind kind2 = new KindImpl(wir, "Hans", "Wurst", Geschlecht.MAENNLICH);
        Kind kind3 = new KindImpl(wir, "Peter", "Zwegat", Geschlecht.MAENNLICH);
        Kind kind4 = new KindImpl(wir, "Manfred", "Meyer", Geschlecht.MAENNLICH);
        Kind kind5 = new KindImpl(wir, "Michael", "Keller", Geschlecht.MAENNLICH);
        Kind kind6 = new KindImpl(ihr, "Hannelore", "Seiler", Geschlecht.WEIBLICH);
        Kind kind7 = new KindImpl(ihr, "Sarah", "K�lln", Geschlecht.WEIBLICH);
        Kind kind8 = new KindImpl(ihr, "Lisa", "Komet", Geschlecht.WEIBLICH);
        Kind kind9 = new KindImpl(ihr, "Karla", "Kyocera", Geschlecht.WEIBLICH);
        Kind kind10 = new KindImpl(ihr, "Renate", "Auricher", Geschlecht.WEIBLICH);


        SuperKigaV.addKind(kind1);
        SuperKigaV.addKind(kind2);
        SuperKigaV.addKind(kind3);
        SuperKigaV.addKind(kind4);
        SuperKigaV.addKind(kind5);
        SuperKigaV.addKind(kind6);
        SuperKigaV.addKind(kind7);
        SuperKigaV.addKind(kind8);
        SuperKigaV.addKind(kind9);
        SuperKigaV.addKind(kind10);

        try {
            SuperKigaV.addKindToGruppe(gruppe1, new AnmeldungImpl(kind1, true, true));
            SuperKigaV.addKindToGruppe(gruppe1, new AnmeldungImpl(kind2, false, false));
            SuperKigaV.addKindToGruppe(gruppe1, new AnmeldungImpl(kind8, false, true));
        } catch (Exception e) {
            System.out.println(e);
        }*/
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JLogin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtPassword;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables

}
